<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>

</head>
<body>
<div>div</div>
<p>p</p>
<div>div</div>
<span>span</span>
<p>p</p>
<div>div</div>

</body>
<script>
    function isArrayLike(obj) {
        if (Object.prototype.toString.call(obj) == '[object Array]') {
            return true;
        }
        var length = 'length' in obj && obj.length;
        return typeof length === 'number' && length >= 0;
    }
    function each(arr, callback) {
        if (isArrayLike(arr)) {
            for (var i = 0; i < arr.length; i++) {
                if (callback.call(arr[i], arr[i], i) === false) break;
            }
        } else {
            for (var k in arr) {
                if (callback.call(arr[k], arr[k], k) === false) break;
            }
        }
        return arr;
    }

//
    var arr = [1, 2, 32, 1, 3, 2, 423, 42, 34, 324, 23,];
    each(arr,function(v,i){
        console.log(this);
        console.log(i + ',' + v);
    })


    var o = {
        name: 'jim',
        age: 19,
        gender: '男'
    };

    each( o, function ( v, i ){
        console.log( this );
        console.log( i + ', ' + v );
    });
</script>
</html>